package com.allianz.webapps.secondController;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.frame.utils.PropertiesUtil;
import com.allianz.frame.utils.StringUtil;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

@Controller
@RequestMapping(value="/main")
public class GetSignController {

	@Autowired
	private ObjectMapper objectMapper;
	
	@RequestMapping(value="/getSign")
	@ResponseBody
	public Map<String,Object> getSign(@RequestParam(value="jsonParam")String jsonParam) throws JsonParseException, JsonMappingException, IOException{
		@SuppressWarnings("unchecked")
		Map<String,Object> map = new HashMap<String,Object>();
		Map<String,Object> param = objectMapper.readValue(jsonParam,Map.class);
		if(param!=null&&param.containsKey("signKey")){
			map.put("sign", StringUtil.getAZCLmd5((String) param.get("signKey"))) ;
		}
		map.put("address", PropertiesUtil.getProperty("quoPdfURLPrefix"));
		return map;
	}
}
